//    Copyright (C) Kherty.  All rights reserved.
using System.Collections.Generic;
using OpenLS.Core.Serialization;

namespace OpenLS.Drawing.Diagram
{
    class DiagramDefinition : IOfficeXmlSerializable
    {
        private List<Name> _titles = new List<Name>();
        List<Description> _descs = new List<Description>();
        private Categories _catLst;
        private string _uniqueId;
        private string _minVer;
        private string _defStyle;
        private SampleData _sampData;
        private SampleData _styleData;
        private SampleData _clrData;
        private LayoutNode _layoutNode;
        private OfficeArtExtensionList _extLst;

        public void ReadXml(ReadContext context)
        {
            using (var c = context.Read("layoutDef"))
            {
                _uniqueId = c.GetOptionalString("uniqueId", string.Empty);
                _minVer = c.GetOptionalString("minVer", Diagram.Serialization.DiagramConstants.DiagramNamespaceUri);
                _defStyle = c.GetOptionalString("defStyle", string.Empty);
                _titles.AddRange(c.ReadOptionalWhile<Name>("title"));
                _descs.AddRange(c.ReadOptionalWhile<Description>("desc"));
                _catLst = c.ReadOptionalElement<Categories>("catLst");
                _sampData = c.ReadOptionalElementAs<SampleData>("sampData");
                _styleData = c.ReadOptionalElementAs<SampleData>("styleData");
                _clrData = c.ReadOptionalElementAs<SampleData>("clrData");
                _layoutNode = c.ReadOptionalElement<LayoutNode>("layoutNode");
                _extLst = c.ReadOptionalElement<OfficeArtExtensionList>("extLst");
            }

        }

        public void WriteXml(WriteContext context)
        {
            using (var c = context.Write("layoutDef"))
            {
                c.SetOptionalString("uniqueId", _uniqueId,string.Empty);
                c.SetOptionalString("minVer", _minVer, "http://schemas.openxmlformats.org/drawingml/2006/diagram");
                c.SetOptionalString("defStyle", _defStyle, string.Empty);
                c.WriteElements(_titles);
                c.WriteElements(_descs);
                c.WriteOptionalElement(_catLst);
                c.WriteOptionalElementAs(_sampData, "sampData");
                c.WriteOptionalElementAs(_styleData, "styleData");
                c.WriteOptionalElementAs(_clrData, "clrData");
                c.WriteOptionalElement(_layoutNode);
                c.WriteOptionalElement(_extLst);
            }
        }
    }
}